package 设计原则;

public class Ocp {
    public static void main(String[] args) {
        GraphicEditor graphicEditor = new GraphicEditor();
        graphicEditor.drawShape(new Rectangle());
        graphicEditor.drawShape(new Circle());
        graphicEditor.drawShape(new Triangle());
        graphicEditor.drawShape(new OtherGraphic());
    }
}

class GraphicEditor {
    public void drawShape(Shape s) {
        s.draw();
    }
}

abstract class Shape{
    int mType;
    public abstract void draw();
}

class Rectangle extends Shape {
    Rectangle(){
        super.mType =1;
    }
    @Override
    public void draw() {
        System.out.println("绘制矩形");
    }
}
class Circle extends Shape {
    Circle(){
        super.mType =2;
    }
    @Override
    public void draw() {
        System.out.println("绘制圆形");
    }
}
class Triangle extends Shape {
    Triangle(){
        super.mType =3;
    }
    @Override
    public void draw() {
        System.out.println("绘制三角形");
    }
}
class OtherGraphic extends Shape{
    OtherGraphic(){
        super.mType =4;
    }
    @Override
    public void draw() {
        System.out.println("绘制其它图形");
    }
}